import { _decorator, Button, Component, director, game, Node, sys } from 'cc';
import { PRIVACY_POLLICY_SWITCH } from './Define';
const { ccclass, property } = _decorator;

@ccclass('BtnManager')
export class BtnManager extends Component {

    @property(Button)
    public cancelBtn:Button = null
    @property(Button)
    public agreeBtn:Button = null

    @property(Node)
    public safeLayer:Node = null

   onLoad(){
        
        this.cancelBtn.node.on(Button.EventType.CLICK,this.onCancel,this)
        this.agreeBtn.node.on(Button.EventType.CLICK,this.onAgreeBtn,this)
   } 

    onDisable() {
        this.cancelBtn.node.off(Button.EventType.CLICK,this.onCancel,this)
        this.agreeBtn.node.off(Button.EventType.CLICK,this.onAgreeBtn,this) 
   }

   onCancel(){
        sys.localStorage.setItem("PRIVACY_POLLICY_SWITCH_STRING",PRIVACY_POLLICY_SWITCH.OFF)
        this.safeLayer.active = false

        game.end()
   }

   onAgreeBtn(){
        sys.localStorage.setItem("PRIVACY_POLLICY_SWITCH_STRING",PRIVACY_POLLICY_SWITCH.ON) 
        this.safeLayer.active = false

   }
}

